package com.fanbuchi.fukua.api;


import com.fanbuchi.fukua.manager.OauthManager;
import com.squareup.okhttp.Callback;
import com.squareup.okhttp.FormEncodingBuilder;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.RequestBody;
/**
 * Created by Administrator on 2015/7/1.
 */
public final class Oauth2API extends API{
    private  static String mOauth2=getHost()+"/auth";
    private  static String authorize=mOauth2;
    private  static String refreshToken=mOauth2+"/refreshToken";
    public static Oauth2API API;

    private  Oauth2API(){
    }
    public static Oauth2API getAPI(){
        if (API==null){
            API = new Oauth2API();
        }
     return API;
    }

    public  void authorize(FormEncodingBuilder builder,Callback callback) {
        normalPostRequest(builder,callback,authorize);
    }


    public  void refreshToken(Callback callback) {
        if (OauthManager.getRefreshToken()==null){
            return;
        }
        Request request = new Request.Builder()
                .url(refreshToken)
                .headers(getNormalHeaders())
                .header("basic", OauthManager.getRefreshToken())
                .header("bearer", "refreshToken")
                .build();
            mClient.newCall(request).enqueue(callback);
    }

}
